/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.table;

import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import simplemetrosystem.view.Layout.GBC;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.action.NewLineActionListener;
import simplemetrosystem.view.action.RemoveLineActionListener;

/**
 *
 * @author Eric Qian
 */
public class AllLineTableToolPane extends JPanel{

    /**
     * 
     * @param infPane
     */
    public AllLineTableToolPane(InformationPane infPane) {
        this.infPane = infPane;
        nameMap = NameMap.getInstance();
        loadComponent();
    }

    private void loadComponent() {
        setLayout(new GridBagLayout());

        add(getNewLineButton(), new GBC(0, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getRemoveLineButton(), new GBC(1, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getSearchPane(), new GBC(2, 0).setWeight(100, 0).setFill(GBC.BOTH));
    }

    private JButton getNewLineButton() {
        if (NewLineButton == null) {
            NewLineButton = new JButton();
            NewLineButton.setText(nameMap.getName("New Line"));
            NewLineButton.setToolTipText(nameMap.getName("New Line"));
            NewLineButton.addActionListener(new NewLineActionListener(infPane.getFrame()));
        }
        return NewLineButton;
    }

    private JButton getRemoveLineButton() {
        if (removeLineButton == null) {
            removeLineButton = new JButton();
            removeLineButton.setText(nameMap.getName("Remove Line"));
            removeLineButton.setToolTipText(nameMap.getName("Remove Line"));
            removeLineListener = new RemoveLineActionListener(infPane.getFrame(),null);
            removeLineButton.addActionListener(removeLineListener);
        }
        return removeLineButton;
    }

    private SearchPane getSearchPane() {
        if (searchPane == null) {
            searchPane = new SearchPane(infPane);
        }
        return searchPane;
    }
    
    private InformationPane infPane;
    private NameMap nameMap;
    private JButton NewLineButton;
    private JButton removeLineButton;
    private SearchPane searchPane;
    private RemoveLineActionListener removeLineListener;
}
